import { NextRequest, NextResponse } from 'next/server';
import { entityDAO } from '@/lib/database';

export async function GET(request: NextRequest) {
  try {
    const { searchParams } = new URL(request.url);
    const specialty = searchParams.get('specialty');
    
    if (!specialty) {
      return NextResponse.json(
        { error: '缺少必要参数: specialty' },
        { status: 400 }
      );
    }
    
    // 查询专业下的所有实体对象
    const entities = entityDAO.findBySpecialty(specialty);
    
    return NextResponse.json({
      success: true,
      data: {
        specialty,
        entities,
        total: entities.length
      }
    });
  } catch (error) {
    console.error('查询实体对象失败:', error);
    return NextResponse.json(
      { 
        error: '查询实体对象失败',
        details: error instanceof Error ? error.message : String(error)
      },
      { status: 500 }
    );
  }
} 